package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.qianyun.QianYunScore;

import com.ucredit.babel.common.model.qianyun.QianYunScoreRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 千云蚁盾分
 *
 * @author rrz
 */
public class QianYunScoreParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 千云蚁盾分
     *
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        QianYunScoreRecord obj = (QianYunScoreRecord) model;
        QianYunScore score = obj.getScore();
        StringBuilder sb = getBaseInfo(obj, successful);

        //请求流水号  orderId
        sb.append(score.getOrderId()).append(CRT001);
        //蚁盾分     score
        sb.append(score.getScore()).append(CRT001);
        StringBuilder txSb = getBaseInfo(obj);
        key.set(getKey());
        val.set((sb.toString() + txSb).replace("\n", "").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_qianyun_score_inc";
    }

    @Override
    public String getType() {
        return RecordType.QIANYUN_SCORE_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "千云蚁盾分";
    }
}
